package team.zero.lemon.module.cms.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import team.zero.lemon.common.authz.annotation.AuthPassport;
import team.zero.lemon.common.persistence.Page;
import team.zero.lemon.common.web.BaseController;
import team.zero.lemon.module.cms.entity.Category;
import team.zero.lemon.module.cms.service.CategoryService;

import java.util.List;

/**
 * Created by bolin on 2016/10/24.
 */
@Controller
@ResponseBody
@AuthPassport
@RequestMapping(value = "/cms/category", method = {RequestMethod.POST, RequestMethod.GET})
public class CategoryController  extends BaseController {
    @Autowired
    private CategoryService categoryService;
    @AuthPassport
    @RequestMapping("/query/all")
    public List<Category> findAllCategory() {
        return categoryService.findAll();
    }
    @AuthPassport
    @RequestMapping("/query/parentId")
    public List<Category> findByParentId(@RequestBody Category category) {
        List<Category> result = categoryService.findByParentId(category);
        return result;
    }
    @AuthPassport
    @RequestMapping("/query/page/parentId")
//    @AuthPermission("sys:org:view")
    public Page<Category> findCategoryByParentId(@RequestBody Category category) {
        return categoryService.findPage(category);
    }
    @AuthPassport
    @RequestMapping("/query/id")
    public Category findById(@RequestBody Category category) {
        return categoryService.findById(category.getId());
    }
    @AuthPassport
    @RequestMapping("/save")
    public int SaveCategory(@RequestBody Category category) {
        return categoryService.save(category);
    }
    @AuthPassport
    @RequestMapping("/delete/ids")
    public int deleteCategory(@RequestBody Category category) {
        return categoryService.deleteLogicMulti(category);
    }
}
